package com.srt.util.exception;

/**
 * @author rd07
 */
public class PBusinessException extends RuntimeException {
    private static final long serialVersionUID = -6543762301978561820L;

    private static final String DEFAULT_FAULT_CODE = "ST0001";

    private String code;
    private String message;

    public PBusinessException(String code, String message, Throwable throwable) {
        this(code, message, throwable.getMessage(), throwable);
    }

    public PBusinessException(String message) {
        this(DEFAULT_FAULT_CODE, message, new Throwable());
    }

    public PBusinessException(String code, String message, String internalMessage) {
        this(code, message, internalMessage, null);
    }

    public PBusinessException(String code, String message, String internalMessage, Throwable throwable) {
        super("[" + code + "] - " + message + internalMessage, throwable);
        this.message = message;
        this.code = code;
    }

    public PBusinessException(String code, String message) {
        this(code, message, new Throwable());
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessageWithoutCode() {
        return message;
    }

    @Override
    public String getMessage() {
        return "[" + code + "]" + " - " + message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
